package com.sanjin.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.*;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Collection;

/**
 * @description:
 * @author: sanjin
 * @date: 2019/5/2 9:51
 */
@Entity
@Table(name = "wx_mini_user", schema = "park", catalog = "")
@Data
public class WxMiniUser implements UserDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String openid;
    private String sessionKey;
    private String nickname;
    private String imageUrl;
    private BigDecimal bonusPoints;
    private String role;
    private String carLicenseNumber;
    private Timestamp createTime;
    private Timestamp updateTime;

    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        // 多个角色，','分隔
        return AuthorityUtils.commaSeparatedStringToAuthorityList(role);
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return null;
    }


    @JsonIgnore
    @Override
    public String getUsername() {
        return openid;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }
}
